<?php $this->load->helper('HTML');
echo link_tag('css/style2.css');
echo link_tag('images/favicon.ico','shortcut icon','image/x-icon');
?>
<div id="page1">
<?php $this->load->view('admin_views/header'); ?>
</head>
<div id="wrapper">
<script type="text/javascript">
    $(document).ready( function() {
								
        $("#intid_unit").autocomplete({
                    minLength: 2,
                    source:
                        function(req, add){
                        $.ajax({
                            url: "<?php echo base_url(); ?>penjualan/lookupUnit",
                            dataType: 'json',
                            type: 'POST',
                            data: req,
                            success:
                                function(data){
                                if(data.response =="true"){
                                    add(data.message);
                                }
                            },
                        });
                    },
                    focus:function(event,ui){var q=$(this).val();$(this).val()=q;},select:
                        function(event, ui) {
                        $("#result2").append(
                        "<input type='hidden' id='id_unit' name='id_unit' value='" + ui.item.id + "' size='10' />"
                    );
                    },
                });


        $("#strnama_dealer").autocomplete({
            minLength: 1,
            source:
                function(req, add){
                $.ajax({
                    url: "<?php echo base_url(); ?>penjualan/lookupUpline",
                    dataType: 'json',
                    type: 'POST',
                    data: {
                     term: req.term,
                     state: $('#id_unit').val(),
                    },
                    success:
                        function(data){
                        if(data.response =="true"){
                            add(data.message);
                        }
                    },
                });
            },
            focus:function(event,ui){var q=$(this).val();$(this).val()=q;},select:
                function(event, ui) {
			$("#result").empty();
                        $("#result").append(
                        "<input type='text' align='top' id='strkode_dealer' name='strkode_dealer' value='" + ui.item.id + "'/><br><td><input type='text' id='strkode_upline' name='strkode_upline' value='" + ui.item.value2 + "'/></td>"
                    );
            },
        });

         $('#submit').click(function() {
		if ($("#loadingScreen").is(":hidden")) {
				$("#loadingScreen").slideUp("slow");
				//$('#message').text('Tutup Form');
		} else {
				
				$("#loadingScreen").slideDown("slow");
				//$('#message').text('Cari Mobil');
		}
									 
 		    var form_data = {
                strkode_dealer : $('#strkode_dealer').val(),
                ajax : '1'
            };
            $.ajax({
                url: "<?php echo base_url(); ?>calon_manager/ranting",
                type: 'POST',
                async : false,
                data: form_data,
				beforeSend: function() {
				$('#message').html('<tr><td colspan=2><?php echo "<img src=".base_url()."images/loading.gif align=absmiddle/>" ?> >> Loading .... Please Wait Several Minutes</td></tr>');	
			},
                success: function(msg) {
                    $('#message').html(msg);
					$('#result').html('');
					$('#result2').html('');
					$('#strnama_dealer').val('');
					$('#intid_unit').val('');
                }
            });
            return false;
        });
    });
	
	
</script>
</div>

<div id="page">
    <div id="page-bgtop">
        <div id="content">
            <div class="post">  <h2 class="title">PILIH MANAGER UNTUK MELIHAT RANTING</h2>

                <form method="post">
                    <table width="95%" border="0" cellpadding="0" cellspacing="0" id="data" align="center">

                        <tr>
                            <td  align='left' style='width:25%' >Pilih Unit</td>
                            <td><input type="text" name="textfield4" id="intid_unit" size="30" /><div id="result2"></div></td>
                        </tr>
                        <tr>
                            <td  align='left' style='width:25%' >Nama Upline</td>
                            <td><input type="text" name="strnama_dealer" id="strnama_dealer" size="60"/></td>
                        </tr>
                        <tr>
                            <td>&nbsp;No Kartu<br /><br />&nbsp;Upline :</td>
                            <td valign="top">&nbsp;<div id="result"></div></td>
                        </tr>
                        <tr>
                            <td><?php echo '<br />'.form_submit('submit','Proses','id="submit" class="button"')?></td>
                        </tr>
                    </table>
                </form>
                <div id="loadingScreen"></div>
                <div id="message"></div>
                
            </div>
        </div>

    </div>
    <!-- end #content -->
    <?php $this->load->view('admin_views/sidebar_manager'); ?><!-- end #sidebar -->
    <div style="clear: both;">&nbsp;</div>
</div>

<!-- end #page -->
<div id="footer-bgcontent">
    <?php $this->load->view('admin_views/footer'); ?></div>
<!-- end #footer -->
